#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <list>
using namespace std;

typedef unsigned int ui32;

int main() {
    int arr[9][9];

    for (int i = 0; i < 9; ++i) {
        for (int j = 0; j < 9; ++j) {
            int tmp;
            scanf("%d", &tmp);
            arr[i][j] = tmp;
        }
    }

    bool ok = true;
    for (int i = 0; i < 9; ++i) {
        ui32 flags = 0;
        for (int j = 0; j < 9; ++j) {
            ui32 mask = 1 << arr[i][j];
            if (flags & mask) {
                ok = false;
                break;
            }
            flags |= mask;
        }
    }

    for (int i = 0; i < 9; ++i) {
        ui32 flags = 0;
        for (int j = 0; j < 9; ++j) {
            ui32 mask = 1 << arr[j][i];
            if (flags & mask) {
                ok = false;
                break;
            }
            flags |= mask;
        }
    }

    for (int i = 0; i < 3; ++i) {
        for (int j = 0; j < 3; ++j) {
            ui32 flags = 0;
            for (int k = 0; k < 3; ++k) {
                for (int p = 0; p < 3; ++p) {
                    ui32 mask = 1 << arr[j+k][i+p];
                    if (flags & mask) {
                        ok = false;
                        break;
                    }
                    flags |= mask;
                }
            }
            
        }
    }

    printf("%s", ok ? "YES" : "NO");

    return 0;
}
